package com.atguigu.study.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * 定义一个切面类
 */
@Aspect
@Component
@Slf4j
public class RequestLogAspect{

    /* 第一种写法：  where的问题，往哪里下刀cut 包名加类名加切入点
    @Pointcut("execution(public * com.atguigu.study.controller.HelloAopController.helloAop(..))")
    public void webLog() {}

    @Before("webLog()")
    public void doBefore(JoinPoint joinPoint) throws Throwable
    {
        System.out.println("---------前置通知:RequestLogAspect");
    }*/

    /**
        1   通知      @Before @AfterReturning
        2   切面类      xxxAspect
        3   连接点 JoinPoint
        4   切入点 PointCut
        5   织入   weave
    */

    //包名加类名加切入点
    @Before("execution(public * com.atguigu.study.controller.HelloAopController.hello*(..))")
    public void doBefore(JoinPoint joinPoint) throws Throwable{

        System.out.println("---------前置通知222:RequestLogAspect----> "+joinPoint.getTarget().getClass().getName());
    }

    @AfterReturning("execution(public * com.atguigu.study.controller.HelloAopController.hello*(..))")
    public void doAfterReturning() throws Throwable {

        System.out.println("---------后置通知:doAfterReturning");
    }
}

